package com.shsh.safemanage.model;

import java.util.Calendar;

import com.shsh.safemanage.util.Constants;
import com.shsh.safemanage.util.Util;

public class Shutdown extends Problem {
	private Integer shutdownTypeID;
	private String shutdownType;
	private String loss;
	private String reason;
	private String duty;
	private String team;
	private Calendar periodStart;
	private Calendar periodEnd;
	private Calendar shutdownWriteTime;
	private Long shutdownWriteUserID;
	private Boolean escalateZongbu;

	public static String getSessionKey(Integer problemType) {
		switch (problemType) {
		case Constants.PROBLEM_TYPE_NOTPLANED_SHUTDOWN:
			return Constants.SESSION_PROBLEM_NOTPLANNED_SHUTDOWN_CONDITION;
		case Constants.PROBLEM_TYPE_TEMP_SHUTDOWN:
			return Constants.SESSION_PROBLEM_TEMP_SHUTDOWN_CONDITION;
		default:
			return null;
		}
	}

	public static String getBrowseSessionKey(Integer problemType) {
		switch (problemType) {
		case Constants.PROBLEM_TYPE_NOTPLANED_SHUTDOWN:
			return Constants.SESSION_NOTPLANNED_SHUTDOWN_CONDITION;
		case Constants.PROBLEM_TYPE_TEMP_SHUTDOWN:
			return Constants.SESSION_TEMP_SHUTDOWN_CONDITION;
		default:
			return null;
		}
	}

	public Shutdown() {

	}

	public Shutdown(Problem problem) {
		super(problem);
	}

	public Boolean getEscalateZongbu() {
		return escalateZongbu;
	}

	public void setEscalateZongbu(Boolean escalateZongbu) {
		this.escalateZongbu = escalateZongbu;
	}

	public Integer getShutdownTypeID() {
		return shutdownTypeID;
	}

	public void setShutdownTypeID(Integer shutdownTypeID) {
		this.shutdownTypeID = shutdownTypeID;
	}

	public String getShutdownType() {
		return shutdownType;
	}

	public void setShutdownType(String shutdownType) {
		this.shutdownType = shutdownType;
	}

	public String getLoss() {
		return loss;
	}

	public void setLoss(String loss) {
		this.loss = loss;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getDuty() {
		return duty;
	}

	public void setDuty(String duty) {
		this.duty = duty;
	}

	public String getTeam() {
		return team;
	}

	public void setTeam(String team) {
		this.team = team;
	}

	public Calendar getPeriodStart() {
		return periodStart;
	}

	public void setPeriodStart(Calendar periodStart) {
		this.periodStart = periodStart;
	}

	public Calendar getPeriodEnd() {
		return periodEnd;
	}

	public void setPeriodEnd(Calendar periodEnd) {
		this.periodEnd = periodEnd;
	}

	public Calendar getShutdownWriteTime() {
		return shutdownWriteTime == null ? getWriteTime() : shutdownWriteTime;
	}

	public void setShutdownWriteTime(Calendar shutdownWriteTime) {
		this.shutdownWriteTime = shutdownWriteTime;
	}

	public Long getShutdownWriteUserID() {
		return shutdownWriteUserID == null ? getWriteUserID() : shutdownWriteUserID;
	}

	public void setShutdownWriteUserID(Long shutdownWriteUserID) {
		this.shutdownWriteUserID = shutdownWriteUserID;
	}

	/**
	 * Return the amount of minutes of the period.
	 * 
	 * @return
	 */
	public Long getPeriodMinutes() {
		if (periodEnd == null || periodStart == null) {
			return 0l;
		}

		return (periodEnd.getTimeInMillis() - periodStart.getTimeInMillis()) / (1000 * 60);
	}

	/**
	 * Return period length with day/hour/minute.
	 * 
	 * @return
	 */
	public long[] getPeriodLength() {
		return Util.getPeriod(getPeriodMinutes());
	}

}
